package com.zj.juc.study.future;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author 自己的名字
 * @version 1.0.0
 * @ClassName ComptableFutureTest
 * @Description future
 * @createTime 2024年12月21日 13:39
 */
public class FutureTaskTest {

    public static void main(String[] args) {
        FutureTask<String> task = new FutureTask<>(new MyThreadCall());
        Thread thread = new Thread(task,"t1");
        thread.start();
        String s = null;
        try {
            s = task.get();
        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        }
        System.out.println("result is"+s);
    }
}

class MyThreadCall implements Callable<String>{
    @Override
    public String call() throws Exception {
        System.out.println("hello world");
        return "hello world";
    }
}